package com.ruoyi.oa.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.oa.domain.ManageGroup;
import com.ruoyi.oa.mapper.ManageGroupMapper;
import com.ruoyi.oa.service.IManageGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 行政组信息 服务层处理
 * 
 * @author ruoyi
 */
@Service
public class ManageGroupServiceImpl implements IManageGroupService
{
    @Autowired
    private ManageGroupMapper groupMapper;

    @Override
    public List<ManageGroup> selectGroupList(ManageGroup group) {
        return this.groupMapper.selectGroupList(group);
    }

    @Override
    public List<ManageGroup> selectGroupAll() {
        return this.groupMapper.selectGroupAll();
    }

    @Override
    public ManageGroup selectGroupById(Long groupId) {
        return this.groupMapper.selectGroupById(groupId);
    }

    @Override
    public int deleteGroupByIds(String ids) {
        Long[] groupIds = Convert.toLongArray(ids);
        return this.groupMapper.deleteGroupByIds(groupIds);
    }

    @Override
    public int insertGroup(ManageGroup group) {
        return this.groupMapper.insertGroup(group);
    }

    @Override
    public int updateGroup(ManageGroup group) {
        return this.groupMapper.updateGroup(group);
    }

    @Override
    public boolean checkGroupNameUnique(ManageGroup group) {
        Long groupId = StringUtils.isNull(group.getGroupId()) ? -1L : group.getGroupId();
        ManageGroup groupInfo = this.groupMapper.checkGroupNameUnique(group.getGroupName());
        if(StringUtils.isNotNull(groupInfo) && groupInfo.getGroupId().longValue() != groupId.longValue()) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public boolean checkGroupCodeUnique(ManageGroup group) {
        Long groupId = StringUtils.isNull(group.getGroupId()) ? -1L : group.getGroupId();
        ManageGroup info = this.groupMapper.checkGroupCodeUnique(group.getGroupCode());
        if (StringUtils.isNotNull(info) && info.getGroupId().longValue() != groupId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }


}
